package com.dongdongshop.service.imp;

import com.alibaba.dubbo.config.annotation.Service;
import com.dongdongshop.mapper.TbBrandMapper;
import com.dongdongshop.mapper.TbSpecificationMapper;
import com.dongdongshop.mapper.TbTypeTemplateMapper;
import com.dongdongshop.page.PageBeen;
import com.dongdongshop.pojo.TbBrand;
import com.dongdongshop.pojo.TbSpecification;
import com.dongdongshop.pojo.TbTypeTemplate;
import com.dongdongshop.service.TbTypeTemplateService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
@org.springframework.stereotype.Service
public class TbTypeTemplateServiceImp implements TbTypeTemplateService {
    @Autowired
    private TbTypeTemplateMapper templateMapper;
    @Autowired
    private TbBrandMapper tbBrandMapper;
    @Autowired
    private TbSpecificationMapper tbSpecificationMapper;

    @Override
    public PageBeen<TbTypeTemplate> getTemplate(String name, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<TbTypeTemplate> list = templateMapper.selectByTemplate(name);
        PageInfo<TbTypeTemplate> pageInfo = new PageInfo<>(list);
        return new PageBeen<>(pageNum,pageSize,pageInfo.getTotal(),pageInfo.getList(),pageInfo.getPages());
    }

    @Override
    public List<TbBrand> selectByBrand() {
        return tbBrandMapper.selectByExample(null);
    }

    @Override
    public List<TbSpecification> selectBySpecification() {
        return tbSpecificationMapper.selectByExample(null);
    }

    @Override
    public int addTemplate(TbTypeTemplate tbTypeTemplate) {
        return templateMapper.insertSelective(tbTypeTemplate);
    }

    @Override
    public TbTypeTemplate toUpdate(Long id) {
        return templateMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateInfo(TbTypeTemplate tbTypeTemplate) {
        int i1 = templateMapper.updateByPrimaryKeySelective(tbTypeTemplate);
        return i1;
    }

    @Override
    public int deleteInfo(Integer[] ids) {
        return templateMapper.deleteInfo(ids);
    }

    @Override
    public TbTypeTemplate getBrand(Long id) {
        return templateMapper.selectByPrimaryKey(id);
    }

    @Override
    public TbTypeTemplate getTemplateMapper(Long typeId) {
        return templateMapper.selectByPrimaryKey(typeId);
    }


}
